package com.neusoft.yuejian_01.adapter;

import android.content.Context;
import android.content.Intent;
import android.support.v7.widget.RecyclerView;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import com.neusoft.yuejian_01.activity.ActivityDetailActivity;
import com.neusoft.yuejian_01.R;
import com.neusoft.yuejian_01.base.BaseAdapter;
import com.neusoft.yuejian_01.javabean.ActivityBean;
import com.neusoft.yuejian_01.model.ConstPhoto;
import com.neusoft.yuejian_01.viewHolder.ActivityViewHolder;

import java.util.List;

import it.sephiroth.android.library.picasso.Picasso;


/**
 * Created by Administrator on 2017/9/28.
 */

public class ActivityAdapter extends BaseAdapter {
    public ActivityAdapter(Context context, List data) {
        super(context,data);
        this.context=context;
    }
    @Override
    protected RecyclerView.ViewHolder onCreateVH(ViewGroup parent, LayoutInflater layoutInflater, int viewType) {
        View itemView = layoutInflater.inflate(R.layout.item_activitylist, parent, false);
        ActivityViewHolder viewHolder = new ActivityViewHolder(itemView);
        return viewHolder;
    }
    @Override
    protected void onBindVH(RecyclerView.ViewHolder holder, List data, int position) {
        ActivityBean activitylist = (ActivityBean) data.get(position);
        ActivityViewHolder viewHolder = (ActivityViewHolder) holder;
        String activityName = activitylist.getA_name();
        final int a_id = activitylist.getA_id();
        viewHolder.activityView.setText(activityName);
        String activityImage = ConstPhoto.BASE_URL+ConstPhoto.ActivityFile+activitylist.getA_picture();
        Picasso.with(context)
                .load(activityImage)
                .placeholder(R.drawable.pic2)
                .into(viewHolder.activtyImage);
        viewHolder.itemView.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                //启动新的activity(活动详情)
                Intent intent = new Intent(context, ActivityDetailActivity.class);
                intent.putExtra("a_id", a_id);
                context.startActivity(intent);
            }
        });
    }
}

